package com.niit.service.impl;

import java.util.List;

import com.niit.bean.User;
import com.niit.dao.UserDao;
import com.niit.dao.impl.UserDaoImpl;
import com.niit.service.UserService;
import com.niit.utils.Page;

public class UserServiceImpl implements UserService {
	
	private UserDao dao = new UserDaoImpl();
	@Override
	public int add(User t) {
		return dao.add(t);
	}

	@Override
	public int delete(User t) {
		return dao.delete(t);
	}

	@Override
	public int update(User t) {
		return dao.update(t);
	}

	@Override
	public Page<User> getPage(String pagenum, String url) {
		int total = dao.findTotal();//查出总记录数
		Page<User> page = null;
		if(pagenum == null){
			page = new Page<User>(total,1);
		}else{
			page = new Page<User>(total, Integer.parseInt(pagenum));
		}
		List<User> list = dao.findAll(page.getStartIndex(), page.getEndIndex());
		page.setList(list);
		page.setUrl(url);
		return page;
	}

	@Override
	public boolean isMobExist(String mobile) {
		return dao.isMobExist(mobile);
	}

	@Override
	public boolean isEmailExist(String email) {
		return dao.isEmailExist(email);
	}

	@Override
	public User login(String username, String password) {
		return dao.login(username, password);
	}
	
	@Override
	public int update(boolean forbid, String username) {
		return dao.update(forbid, username);
	}

	@Override
	public int findTotal() {
		return dao.findTotal();
	}


}
